package com.uni.domain;

import org.hibernate.Hibernate;

import java.io.Serializable;

public class Identifier implements Serializable, Identifiable {

    private Long id = -1l;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Checks that id is less then 1
     */
    public boolean isNew() {
        return id < 1;
    }

    /**
     * Checks that id is great then 0
     */
    public static boolean isValid(Number num) {
        return num.longValue() > 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        } else if (obj == null || !(Hibernate.getClass(obj).equals(Hibernate.getClass(this)))) {
            return false;
        } else {
            Identifier other = (Identifier) obj;
            if (other.getId() < 0) {
                return false;
            } else {
                return this.getId() == other.getId();
            }
        }
    }

    @Override
    public int hashCode() {
        return id.intValue();
    }

}
